package org.wx.io.netty.tcp.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import lombok.extern.slf4j.Slf4j;
import org.wx.io.netty.tcp.codec.MyTcpProtocol;

import java.nio.charset.Charset;

/**
 * @description:
 * @author: wangxun
 * @createDate: 2021/2/22
 * @version: 1.0
 */
@Slf4j
public class TcpServerHandler extends SimpleChannelInboundHandler<MyTcpProtocol> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyTcpProtocol msg) throws Exception {
        String content = new String(msg.getContent(), Charset.forName("utf-8"));

        log.info("TcpServerHandler接收到数据 命令是:{} 数据包长度:{} 内容是:{}",
              msg.getCommand(),msg.getPackageLength(),content);
    }
}
